<?php
$attrs = [
    ["value" => "颜色", "detail" => ["蓝色", "白色"]],
    ["value" => "尺寸", "detail" => ["XL", "S", "M", "XXL", "XXXL"]],
    ["value" => "年龄", "detail" => ["3", "5", "7", "9", "3-4"]],
    ["value" => "ddd", "detail" => ["a", "b", "d", "f", "3-ee"]]
];


$result = [];

function formatAttrValues($attrs = [], $i = 0){
    global $result;
    if (!isset($attrs[$i])) {
        return;
    }
    for ($j = 0; $j < count($attrs[$i]["detail"]); $j++) {
        if (!empty($result) && count($result[count($result) - 1]) < count($attrs)) {
            $result[count($result) - 1][$attrs[$i]["value"]] = $attrs[$i]["detail"][$j];
        }else if ($i != 0){
            $row = $result[count($result) - 1];
            $row = array_slice($row, 0, $i+1);
            $row[$attrs[$i]["value"]] = $attrs[$i]["detail"][$j];
            $result[] = $row;
        }else{
            $result[] = [
                $attrs[$i]["value"] => $attrs[$i]["detail"][$j]
            ];
        }

        formatAttrValues($attrs, $i+1);
    }
}

formatAttrValues($attrs);

echo count($result);